﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:clr="clr-namespace:System;assembly=mscorlib" 
                    xmlns:clr2="clr-namespace:System.Collections;assembly=mscorlib" 
                    xmlns:generics="clr-namespace:System.Collections.Generic;assembly=mscorlib"
                    xmlns:local="clr-namespace:WPG"                     
                    xmlns:data="clr-namespace:WPG.Data" 
                    xmlns:converters="clr-namespace:WPG.Converters" 
                    xmlns:typeeditors="clr-namespace:WPG.TypeEditors" 
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2006" 
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:TypeEditors="clr-namespace:WPG.Themes.TypeEditors">

	<!--******************************-->
	<!--    DataTemplates             -->
	<!--******************************-->

	<DataTemplate DataType="{x:Type data:PropertyCollection}">
		<ItemsControl ItemsSource="{Binding Path=Items}" />
	</DataTemplate>

	<DataTemplate DataType="{x:Type data:PropertyCategory}">
		<Expander Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ExpanderStyle}}" Header="{Binding Category}" IsExpanded="True">
			<!-- Grid.IsSharedSizeScope="True"> -->
			<ItemsControl ItemsSource="{Binding Path=Items}" />
		</Expander>
	</DataTemplate>

	<DataTemplate DataType="{x:Type data:ExpandableProperty}">
		<Expander Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ExpanderStyle}}" Header="{Binding Name}" IsExpanded="False">
			<!-- Grid.IsSharedSizeScope="True"> -->
			<ItemsControl ItemsSource="{Binding Path=Items}" />
		</Expander>
	</DataTemplate>

	<local:PropertyTemplateSelector x:Key="propertyTemplateSelector" />

	<!--
    <DataTemplate DataType="{x:Type data:Property}">
        <Grid Margin="4" Width="Auto" HorizontalAlignment="Stretch">
            <Grid.RowDefinitions/>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <SharedSizeGroup="PropertyGridItemName"/>
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock Grid.Column="0"  Margin="0,0,8,0" TextAlignment="Right" VerticalAlignment="Center" Text="{Binding Mode=OneTime, Path=Name}" />
            <ContentControl Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Content="{Binding Mode=OneWay}" ContentTemplateSelector="{StaticResource propertyTemplateSelector}" />
        </Grid>
    </DataTemplate>
    -->
    
	<DataTemplate DataType="{x:Type data:Property}">
		<DockPanel Margin="4">
			<TextBlock Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBlockStyle}}" DockPanel.Dock="Left" Width="80" Margin="0,0,8,0" TextAlignment="Right" VerticalAlignment="Center" Text="{Binding Mode=OneTime, Path=Name}">
				<TextBlock.ToolTip>
					<ToolTip>
						<ToolTip.Content>
							<StackPanel>
								<StackPanel Orientation="Horizontal">
									<TextBlock Text="{Binding Mode=OneTime, Path=Name}" Padding="1 0 0 0" />
									<TextBlock Text=": " Padding="1 0 0 0" />
									<TextBlock Text="{Binding Mode=OneTime, Path=PropertyType}" FontWeight="Bold" Padding="1 0 0 0" />
								</StackPanel>
								<TextBlock Text="{Binding Mode=OneTime, Path=Description}" Padding="1 1 0 0" />
							</StackPanel>
						</ToolTip.Content>
					</ToolTip>
				</TextBlock.ToolTip>
			</TextBlock>
			<ContentControl VerticalAlignment="Center" Content="{Binding Mode=OneWay}" ContentTemplateSelector="{StaticResource propertyTemplateSelector}" />
		</DockPanel>
	</DataTemplate>        

	<!-- CLR & Custom Types Data Templates -->
	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=default}">
		<TextBox IsReadOnly="{Binding Path=IsReadOnly}" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBoxStyle}}">
			<TextBox.Text>
				<Binding Mode="TwoWay" Path="Value">
					<Binding.ValidationRules>
						<ExceptionValidationRule />
					</Binding.ValidationRules>
				</Binding>
			</TextBox.Text>
		</TextBox>
	</DataTemplate>

    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type generics:List`1[System.Object]}}">
        <TypeEditors:CollectionEditorControl NumerableType="{Binding Path=PropertyType}" NumerableValue="{Binding Path=Value}" MyProperty="{Binding}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></TypeEditors:CollectionEditorControl>
    </DataTemplate>

    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type Brush}}">
        <TypeEditors:BrushEditorControl Brush="{Binding Path=Value}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></TypeEditors:BrushEditorControl>
    </DataTemplate>
        
    <DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Int32}}">
        <typeeditors:IntegerTypeEditor Text="{Binding Path=Value,UpdateSourceTrigger=PropertyChanged}" IsReadOnly="{Binding Path=IsReadOnly}" Foreground="Black"></typeeditors:IntegerTypeEditor>
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Boolean}}">
		<CheckBox Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=CheckBoxStyle}}" IsEnabled="{Binding Path=IsWriteable}" IsChecked="{Binding Path=Value}" />
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr2:IList}}">
		<!-- Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ListBoxStyle}}" -->
		<ListBox ItemsSource="{Binding Path=Value}" />
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Enum}}">
		<ComboBox Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=ComboBoxStyle}}" SelectedValue="{Binding Path=Value}">
			<ComboBox.ItemsSource>
				<Binding Path="Value">
					<Binding.Converter>
						<converters:EnumTypeConverter />
					</Binding.Converter>
				</Binding>
			</ComboBox.ItemsSource>
		</ComboBox>
	</DataTemplate>

	<DataTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId={x:Type clr:Double}}">
		<TextBox IsReadOnly="{Binding Path=IsReadOnly}" Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type local:PropertyGrid}, ResourceId=TextBoxStyle}}">
			<TextBox.Text>
				<Binding Mode="TwoWay" Path="Value">
					<Binding.Converter>
						<converters:DoubleTypeConverter />
					</Binding.Converter>
				</Binding>
			</TextBox.Text>
		</TextBox>
	</DataTemplate>

</ResourceDictionary>